//历史浏览页
//author:王梦阳

var userId = localStorage.getItem("user"); //用户id
let getHistory = {
	version: "v1.0",
	getHistoryInfo: function() {
		let dataset;
		$.ajax({
			type: "GET",
			dataType: "json",
			contentType: "application/json",
			url: "http://39.98.158.247:8040/browse/get",
			data: {
				userId: userId,
			},
			success: function(data) {
				console.log(data);
				console.log(JSON.stringify(data));
				let itemId = "";
				let htmlContent = "";
				for (var i = 0; i < data.data.length; i++) {
					itemId = data.data[i].item_id;
					htmlContent +=
						`<div class="item"id="${itemId}" >
									<img  class="item-image" src="${data.data[i].item_img}"/>
									<div class="item-content">
										<span class="item-title">${data.data[i].item_name}</span>
										<span class="item-shop">${data.data[i].item_brand}</span>
										<span class="item-price">￥${data.data[i].item_price}</span>
										<span class="item-sale">已售 ${data.data[i].item_sales} 件</span>
									</div>
								</div>`;
					$("#item-list").html(htmlContent);

				}
				for (var j = 0; j < data.data.length; j++) {
					itemId = data.data[j].item_id;
					document.getElementById(itemId).addEventListener('tap', function() {
						window.open("search-item.html", "_blank");
						localStorage.status = 0;
						localStorage.id = this.id;
					})
				}

			},
			error: function() {
				console.log("request error");
			}

		})
	}
}

window.onload = function() {
	getHistory.getHistoryInfo();
}
